﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.BLL.GoodsDelivery;

namespace ERPGoodsDelivery.Delivery
{
    public partial class FrmSelectUser : Form
    {
        //参数
        private GoodsDeliveryBLL bll = new GoodsDeliveryBLL();

        //属性
        public FrmDeliveryMain main { get; set; }
        public int DeliverId { get; set; }
        public int UserId { get; set; }

        public FrmSelectUser()
        {
            InitializeComponent();
        }

        private void FrmSelectUser_Load(object sender, EventArgs e)
        {
            SetDeliverWorkerInfo();
        }

        //确定按钮
        private void btnOk_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            UserId = Convert.ToInt32(this.cbDeliverPeople.SelectedValue);
            string userName = this.cbDeliverPeople.Text;
            string deliveryRemark = txtDeliveryRemark.Text;
            DataTable dt = CreateDeliveryDT();
            DataRow row = dt.NewRow();
            row["DeliveryId"] = DeliverId;
            row["UserName"] = userName;
            row["Remark"] = deliveryRemark;
            dt.Rows.Add(row);
            main.DeliveryDT = dt;
            this.Close();
        }

        //-------------------------------------公共方法----------------------------------------
        /// <summary>
        /// 设置运货的员工
        /// </summary>
        public void SetDeliverWorkerInfo()
        {
            try
            {
                DataTable dt = bll.GetDeliveryWorkers();
                cbDeliverPeople.DisplayMember = "UserName";
                cbDeliverPeople.ValueMember = "UserId";
                cbDeliverPeople.DataSource = dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 创建发货单的整体信息结构
        /// </summary>
        /// <returns></returns>
        public DataTable CreateDeliveryDT()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("DeliveryId",typeof(int)));
            dt.Columns.Add(new DataColumn("UserName",typeof(string)));
            dt.Columns.Add(new DataColumn("Remark",typeof(string)));
            return dt;
        }
    }
}
